<?php

namespace Acesso\Model\AbstractTable;

use Zend\Db\Adapter\Adapter;
use Zend\Db\TableGateway\AbstractTableGateway as AbstractTableGateway;
use Zend\Db\Adapter\AdapterAwareInterface as AdapterAwareInterface;

class Login extends AbstractTableGateway implements AdapterAwareInterface
{

    protected $table;

    public function __construct( Adapter $adapter )
    {
        $this->table = new \Zend\Db\Sql\TableIdentifier( 'login' );
        $this->setDbAdapter( $adapter );

    }

    public function setDbAdapter( Adapter $adapter )
    {
        $this->adapter = $adapter;
        $this->initialize();

    }

    public function fetchAll()
    {
        $resultset = $this->select();
        return $resultset->toArray();

    }

    public function fetchRow( $data )
    {
        $resultset = $this->select( $data );
        return $resultset->toArray();

    }

    public function updateUsuario( $data, $id )
    {
        $this->update( $data, array('id' => $id) );

    }

    public function insert( $data )
    {
        $this->insert( $data );
        //you can return lastId for Your App need
        return $this->getLastInsertValue();

    }

    public function delete( $id )
    {
        $rowset = $this->select( array('id' => $id) );
        $row    = $rowset->current();

        $row->delete();

    }

}
